package com.woniuxy.intellihome.mapper;

import com.woniuxy.intellihome.entity.GoodsSpu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author jobob
 * @author ganrun 2021-8-16
 * @since 2021-08-11
 */
public interface GoodsSpuMapper extends BaseMapper<GoodsSpu> {
    /**
     * 查找最新商品信息
     */
    @Select("SELECT id,name,num,up_time AS upTime,category_id AS categoryId,description,preview,isnew,ishot,status,down_time AS downTime from m_goods_spu where status ='y' and isnew = 'y';")
    List<GoodsSpu> getNew();
    /**
     * 查找最热商品信息
     */
    @Select("SELECT id,name,num,up_time AS upTime,category_id AS categoryId,description,preview,isnew,ishot,status,down_time AS downTime from m_goods_spu where status ='y' and ishot = 'y';")
    List<GoodsSpu> getHot();
    /**
     * 查找商品分类类型
     */
    @Select("SELECT * from m_goods_spu gs,m_category c where c.id = gs.category_id and c.id = #{categoryId} and c.STATUS = 'y';")
    List<GoodsSpu> listByCategory(int categoryId);

    /**
     * 根据skuId得到Spu
     * @param skuId skuId
     * @return 隶属于sku的spu
     */
    @Select("SELECT gs.* \n" +
            "FROM m_goods_spu gs,`m_goods_spec_detail` gsd\n" +
            "WHERE gsd.goods_id=gs.id AND gsd.sku_id=#{skuId} LIMIT 1")
    GoodsSpu getSpuBelong2Sku(int skuId);

}
